Repository navigation
Conversation
The Experiments screen rendered every toggle as "off" whenever the saved `gutenberg-experiments` option contained a key that is not a currently registered experiment. This is easy to hit in practice: switching between branches that register different experiments leaves stale keys behind. `WP_REST_Settings_Controller::get_registered_options()` runs each registered schema through `rest_default_additional_properties_to_false()`, which stamps `additionalProperties => false` onto any object schema that does not set it. `prepare_value()` then validates the stored option against that schema and returns null when validation fails, so one stale key blanked out the whole option in `GET /wp/v2/settings` and the screen had no values left to render. The failure was both closed and silent, which is what made it worth fixing rather than working around: the user saw a plausible-looking screen that was simply wrong, and toggling anything on would then write back a value that dropped their other settings. Set `additionalProperties` to true so the stored value survives validation intact. Unknown keys are preserved rather than stripped, because they usually belong to a branch the user can switch back to, and discarding them would silently lose settings they never asked to change. Since the schema now accepts arbitrary properties on write, a `sanitize_callback` normalises what gets persisted to a flat map of booleans. On the client, a null value is now distinguished from "nothing is enabled". When the stored value cannot be read the page shows an error notice instead of the form, because rendering toggles from an unknown state would let a single click overwrite whatever is really stored. That closes the silent failure for any remaining cause, not just stale keys. Note that phpunit/bootstrap.php has been seeding this option with four keys that are no longer registered, so the test fixture was hitting this too. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Size Change: 0 B Total Size: 7.91 MB |
Contributor
Author
|
Closing this one for lack of interest. We can always resurrect if someone wants to. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fair warning: This PR is largely Claude-authored as a fix to an issue I experience in an unrelated session. Which is that if an experiment key exists but isn't registered as an experiment.
Therefore honestly success could be a very quick glance at this PR and a dev saying "nah, it's fine". But in case it's helpful, I'll pass it over to Claude.
The Experiments screen rendered every toggle as "off" whenever the saved
gutenberg-experimentsoption contained a key that is not a currently registered experiment. This is easy to hit in practice: switching between branches that register different experiments leaves stale keys behind.WP_REST_Settings_Controller::get_registered_options()runs each registered schema throughrest_default_additional_properties_to_false(), which stampsadditionalProperties => falseonto any object schema that does not set it.prepare_value()then validates the stored option against that schema and returns null when validation fails, so one stale key blanked out the whole option inGET /wp/v2/settingsand the screen had no values left to render.The failure was both closed and silent, which is what made it worth fixing rather than working around: the user saw a plausible-looking screen that was simply wrong, and toggling anything on would then write back a value that dropped their other settings.
Set
additionalPropertiesto true so the stored value survives validation intact. Unknown keys are preserved rather than stripped, because they usually belong to a branch the user can switch back to, and discarding them would silently lose settings they never asked to change. Since the schema now accepts arbitrary properties on write, asanitize_callbacknormalises what gets persisted to a flat map of booleans.On the client, a null value is now distinguished from "nothing is enabled". When the stored value cannot be read the page shows an error notice instead of the form, because rendering toggles from an unknown state would let a single click overwrite whatever is really stored. That closes the silent failure for any remaining cause, not just stale keys.
Note that phpunit/bootstrap.php has been seeding this option with four keys that are no longer registered, so the test fixture was hitting this too.
Use of AI Tools
Claude Opus 5.